# core/app_launcher.py
import sys
from PyQt5 import QtWidgets
from ui.config_dialog import ConfigDialog
from ui.log_window import LogWindow
from core.logger_config import setup_logger
from game_components.game_automation import GameAutomation, GameAutomationWorker
from loguru import logger
from utils.path_helper import resource_path

class MainApplication(QtWidgets.QApplication):
    def __init__(self, args):
        super().__init__(args)
        self.automation = None
        self.worker = None
        self.log_window = None
        self.log_path = resource_path("logs/game_automation.log")

    def start_application(self):
        dialog = ConfigDialog()
        result = dialog.exec_()

        if result == QtWidgets.QDialog.Accepted:
            config = dialog.result_config
            logger.info(f"用户配置: {config}")

            self.automation = GameAutomation(config)
            self.log_window = LogWindow(self.log_path)
            self.log_window.show()

            self.worker = GameAutomationWorker(self.automation)
            self.worker.start()
        else:
            logger.info("用户取消了配置")
            self.quit()